﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.Text;

namespace Utility
{
	// Token: 0x02000629 RID: 1577
	public static class File
	{
		// Token: 0x060025C9 RID: 9673 RVA: 0x001452C8 File Offset: 0x001434C8
		public static string[] Gets(string filePath, string searchFile)
		{
			List<string> list = new List<string>();
			if (Directory.Exists(filePath))
			{
				foreach (string path in Directory.GetDirectories(filePath))
				{
					list.AddRange(Directory.GetFiles(path, searchFile));
				}
			}
			return list.ToArray();
		}

		// Token: 0x060025CA RID: 9674 RVA: 0x00145318 File Offset: 0x00143518
		public static void GetAllFiles(string folder, string searchPattern, ref List<string> files)
		{
			files.AddRange(Directory.GetFiles(folder, searchPattern));
			foreach (string folder2 in Directory.GetDirectories(folder))
			{
				File.GetAllFiles(folder2, searchPattern, ref files);
			}
		}

        public static bool Exists(string path)
        {
            return System.IO.File.Exists(path);
        }

		// Token: 0x060025CB RID: 9675 RVA: 0x0014535C File Offset: 0x0014355C
		public static string ConvertPath(string path)
		{
			return path.Replace("\\", "/");
		}

		// Token: 0x060025CC RID: 9676 RVA: 0x00145370 File Offset: 0x00143570
		public static object LoadFromBinaryFile(string path)
		{
			object result = null;
			using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
			{
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				result = binaryFormatter.Deserialize(fileStream);
			}
			return result;
		}

		// Token: 0x060025CD RID: 9677 RVA: 0x001453BC File Offset: 0x001435BC
		public static void SaveToBinaryFile(object obj, string path)
		{
			using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
			{
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				binaryFormatter.Serialize(fileStream, obj);
			}
		}

		// Token: 0x060025CE RID: 9678 RVA: 0x00145404 File Offset: 0x00143604
		public static bool OpenRead(string filePath, Action<FileStream> act)
		{
			if (!System.IO.File.Exists(filePath))
			{
				return false;
			}
			using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
			{
				act(fileStream);
			}
			return true;
		}

		// Token: 0x060025CF RID: 9679 RVA: 0x00145454 File Offset: 0x00143654
		public static void OpenWrite(string filePath, bool isAppend, Action<FileStream> act)
		{
			using (FileStream fileStream = new FileStream(filePath, (!isAppend) ? FileMode.Create : FileMode.Append))
			{
				act(fileStream);
			}
		}

		// Token: 0x060025D0 RID: 9680 RVA: 0x001454A0 File Offset: 0x001436A0
		public static bool Read(string filePath, Action<StreamReader> act)
		{
			return File.OpenRead(filePath, delegate(FileStream fs)
			{
				using (StreamReader streamReader = new StreamReader(fs))
				{
					act(streamReader);
				}
			});
		}

		// Token: 0x060025D1 RID: 9681 RVA: 0x001454CC File Offset: 0x001436CC
		public static void Write(string filePath, bool isAppend, Action<StreamWriter> act)
		{
			File.OpenWrite(filePath, isAppend, delegate(FileStream fs)
			{
				using (StreamWriter streamWriter = new StreamWriter(fs))
				{
					act(streamWriter);
				}
			});
		}

		// Token: 0x060025D2 RID: 9682 RVA: 0x001454FC File Offset: 0x001436FC
		public static bool ReadCrypto(string filePath, Action<BinaryReader> act)
		{
			return File.OpenRead(filePath, delegate(FileStream fs)
			{
				TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
				global::CryptoAssist cryptoAssist = new global::CryptoAssist();
				using (CryptoStream cryptoStream = new CryptoStream(fs, tripleDESCryptoServiceProvider.CreateDecryptor(cryptoAssist.Key, cryptoAssist.IV), CryptoStreamMode.Read))
				{
					using (BinaryReader binaryReader = new BinaryReader(cryptoStream, Encoding.UTF8))
					{
						act(binaryReader);
					}
				}
			});
		}

		// Token: 0x060025D3 RID: 9683 RVA: 0x00145528 File Offset: 0x00143728
		public static void WriteCrypto(string filePath, bool isAppend, Action<BinaryWriter> act)
		{
			File.OpenWrite(filePath, isAppend, delegate(FileStream fs)
			{
				TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
				global::CryptoAssist cryptoAssist = new global::CryptoAssist();
				using (CryptoStream cryptoStream = new CryptoStream(fs, tripleDESCryptoServiceProvider.CreateEncryptor(cryptoAssist.Key, cryptoAssist.IV), CryptoStreamMode.Write))
				{
					using (BinaryWriter binaryWriter = new BinaryWriter(cryptoStream, Encoding.UTF8))
					{
						act(binaryWriter);
					}
				}
			});
		}
	}
}
